package com.ixoko.swagger.controller.guider;

import com.alibaba.fastjson.JSONObject;
import com.ixoko.swagger.dto.BaseReqDto;
import com.ixoko.swagger.dto.BaseResDto;
import com.ixoko.swagger.req.*;
import com.ixoko.swagger.resp.*;
import com.ixoko.swagger.util.HttpClientUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.ExecutionException;

/**
 * @author luojie
 * @Date 2018/7/1
 */
@Api(description = "私人导游相关接口")
@RestController
@RequestMapping("/tourism/guider")
public class GuiderController {

    @Value("${http.client.base.url}")
    private String baseUrl;


    @RequestMapping("/apply")
    @ApiOperation(value = "私人导游申请接口基础数据预请求接口", httpMethod = "GET")
    public String apply(HttpServletRequest request) throws IOException, ExecutionException {
        String url = baseUrl + "/guider/apply";

        String post = HttpClientUtil.post(url, "");

        return post;
    }

    @RequestMapping(value = "/save/basic")
    @ApiOperation(value = "添加私人导游基本信息接口", httpMethod = "POST", produces = "*/*", consumes = "*/*")
    public String saveBasic(ClientGuiderSaveBasicReqDto reqDto) throws IOException, ExecutionException {
        String url = baseUrl + "/guider/save/basic";

        String post = HttpClientUtil.post(url, JSONObject.toJSONString(reqDto));
        return post;
    }

    @ApiOperation(value = "保存私人导游当地信息", httpMethod = "POST")
    @RequestMapping(value = "/save/local")
    public String saveLocal(ClientGuiderSaveLocalReqDto reqDto) throws IOException, ExecutionException {
        String url = baseUrl + "/guider/save/local";
        String post = HttpClientUtil.post(url, JSONObject.toJSONString(reqDto));
        return post;
    }

    @ApiOperation(value = "保存私人导游个人信息", httpMethod = "POST")
    @RequestMapping(value = "/save/detail")
    public String saveDetail(ClientGuiderSaveDetailReqDto reqDto) throws IOException, ExecutionException {
        String url = baseUrl + "/guider/save/detail";
        String post = HttpClientUtil.post(url, JSONObject.toJSONString(reqDto));
        return post;
    }

    @ApiOperation(value = "私人导游基本信息获取接口", httpMethod = "GET")
    @RequestMapping("/basic/get")
    public BaseResDto<GetClientGuiderBasicRespDto> basicGet() throws IOException, ExecutionException {
        String url = baseUrl + "/guider/basic/get";
        String post = HttpClientUtil.post(url, "");
        BaseResDto<GetClientGuiderBasicRespDto> resDto = JSONObject.parseObject(post, BaseResDto.class);
        resDto.setData(JSONObject.parseObject(JSONObject.parseObject(post).getString("data"), GetClientGuiderBasicRespDto.class));
        return resDto;
    }

    @ApiOperation(value = "私人导游编辑接口", httpMethod = "POST")
    @RequestMapping(value = "/update")
    public String update(ClientGuiderUpdateReqDto reqDto) throws IOException, ExecutionException {
        String url = baseUrl + "/guider/update";
        String post = HttpClientUtil.post(url, JSONObject.toJSONString(reqDto));
        return post;
    }

    @ApiOperation(value = "用户私人导游服务信息获取接口", httpMethod = "GET")
    @RequestMapping(value = "/getService")
    public BaseResDto<ClientGuiderServiceUpdateRespDto> getService() throws IOException, ExecutionException {
        String url = baseUrl + "/guider/getService";
        String post = HttpClientUtil.post(url, "");
        BaseResDto<ClientGuiderServiceUpdateRespDto> resDto = JSONObject.parseObject(post, BaseResDto.class);
        resDto.setData(JSONObject.parseObject(JSONObject.parseObject(post).getString("data"), ClientGuiderServiceUpdateRespDto.class));
        return resDto;
    }

    @ApiOperation(value = "用户私人导游服务信息保存接口", httpMethod = "POST")
    @RequestMapping(value = "/saveService")
    public String saveService(ClientGuiderServiceSaveReqDto reqDto) throws IOException, ExecutionException {
        String url = baseUrl + "/guider/saveService";
        String post = HttpClientUtil.post(url, JSONObject.toJSONString(reqDto));
        return post;
    }

    @ApiOperation(value = "用户保存私人导游个人相册以及自我介绍接口", httpMethod = "POST")
    @RequestMapping(value = "/save/description")
    public String saveDescription(ClientGuiderPicReqDto reqDto) throws IOException, ExecutionException {
        String url = baseUrl + "/guider/save/description";
        String post = HttpClientUtil.post(url, JSONObject.toJSONString(reqDto));
        return post;
    }

    @ApiOperation(value = "用户获取私人导游个人相册以及自我介绍信息", httpMethod = "POST")
    @RequestMapping(value = "/get/description")
    public BaseResDto<ClientGuiderPicRespDto> getDescription() throws IOException, ExecutionException {
        String url = baseUrl + "/guider/get/description";
        String post = HttpClientUtil.post(url, "");
        BaseResDto<ClientGuiderPicRespDto> resDto = JSONObject.parseObject(post, BaseResDto.class);
        resDto.setData(JSONObject.parseObject(JSONObject.parseObject(post).getString("data"), ClientGuiderPicRespDto.class));
        return resDto;
    }

    @ApiOperation(value = "私人导游列表获取", httpMethod = "POST")
    @RequestMapping(value = "/list")
    public BaseResDto<List<ClientGuiderPageByCurrPlaceRespDto>> list(ClientGuiderListReqDto reqDto) throws IOException, ExecutionException {
        String url = baseUrl + "/guider/list";
        String post = HttpClientUtil.post(url, "");
        BaseResDto<List<ClientGuiderPageByCurrPlaceRespDto>> resDto = JSONObject.parseObject(post, BaseResDto.class);
        resDto.setData(JSONObject.parseArray(JSONObject.parseObject(post).getString("data"), ClientGuiderPageByCurrPlaceRespDto.class));
        return resDto;
    }

    @ApiOperation(value = "私人导游详细资料获取", httpMethod = "POST")
    @ApiImplicitParam(name = "id", value = "攻略id", required = true)
    @RequestMapping(value = "detail")
    public BaseResDto<ClientGuiderDetailRespDto> detail(Long id) throws IOException, ExecutionException {
        String url = baseUrl + "/guider/detail";
        HashMap<String, Long> hashMap = new HashMap<>(16);
        hashMap.put("id", id);
        String post = HttpClientUtil.post(url, JSONObject.toJSONString(hashMap));
        BaseResDto<ClientGuiderDetailRespDto> resDto = JSONObject.parseObject(post, BaseResDto.class);
        resDto.setData(JSONObject.parseObject(JSONObject.parseObject(post).getString("data"), ClientGuiderDetailRespDto.class));
        return resDto;
    }


    @ApiOperation(value = "私人导游分享", httpMethod = "POST")
    @ApiImplicitParam(name = "id", value = "攻略id", required = true)
    @RequestMapping("/share")
    public String share(Long id) throws IOException, ExecutionException {
        String url = baseUrl + "/guider/share";
        HashMap<String, Long> hashMap = new HashMap<>(16);
        hashMap.put("id", id);
        String post = HttpClientUtil.post(url, JSONObject.toJSONString(hashMap));
        return post;
    }

    @ApiOperation(value = "获取我的私人导游收藏列表", httpMethod = "POST")
    @RequestMapping("/collect/list")
    public BaseResDto<List<ClientGuiderCollectPageByUserIdRespDto>> collectList(BaseReqDto reqDto) throws IOException, ExecutionException {
        String url = baseUrl + "/guider/collect/list";
        String post = HttpClientUtil.post(url, JSONObject.toJSONString(reqDto));
        BaseResDto<List<ClientGuiderCollectPageByUserIdRespDto>> resDto = JSONObject.parseObject(post, BaseResDto.class);
        resDto.setData(JSONObject.parseArray(JSONObject.parseObject(post).getString("data"), ClientGuiderCollectPageByUserIdRespDto.class));
        return resDto;
    }

    @ApiOperation(value = "导游收藏接口", httpMethod = "POST")
    @ApiImplicitParam(name = "id", value = "私人导游id", required = true)
    @RequestMapping("/collect")
    public String collect(Long id) throws IOException, ExecutionException {
        String url = baseUrl + "/guider/collect";
        HashMap<String, Long> hashMap = new HashMap<>(16);
        hashMap.put("id", id);
        String post = HttpClientUtil.post(url, JSONObject.toJSONString(hashMap));
        return post;
    }

    @ApiOperation(value = "导游收藏取消接口", httpMethod = "POST")
    @ApiImplicitParam(name = "id", value = "私人导游id", required = true)
    @RequestMapping("/remove/collect")
    public String removeCollect(Long id) throws IOException, ExecutionException {
        String url = baseUrl + "/guider/remove/collect";
        HashMap<String, Long> hashMap = new HashMap<>(16);
        hashMap.put("id", id);
        String post = HttpClientUtil.post(url, JSONObject.toJSONString(hashMap));
        return post;
    }

    @ApiOperation(value = "导游评论接口", httpMethod = "POST")
    @RequestMapping("/releaseAssess")
    public String releaseAssess(ClientGuiderAssessReqDto reqDto) throws IOException, ExecutionException {
        String url = baseUrl + "/guider/releaseAssess";
        String post = HttpClientUtil.post(url, JSONObject.toJSONString(reqDto));
        return post;
    }

    @ApiOperation(value = "导游评论删除接口", httpMethod = "POST")
    @ApiImplicitParam(name = "assessId", value = "评论信息id", required = true)
    @RequestMapping("/removeAssess")
    public String removeAssess(Long assessId) throws IOException, ExecutionException {
        String url = baseUrl + "/guider/removeAssess";
        HashMap<String, Long> hashMap = new HashMap<>(16);
        hashMap.put("assessId", assessId);
        String post = HttpClientUtil.post(url, JSONObject.toJSONString(hashMap));
        return post;
    }

    @ApiOperation(value = "导游评论回复接口", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "assessId", value = "评论信息id", required = true),
            @ApiImplicitParam(name = "replyContent", value = "评论内容", required = true)
    })
    @RequestMapping("/replyAssess")
    public String replyAssess(Long assessId, String replyContent) throws IOException, ExecutionException {
        String url = baseUrl + "/guider/replyAssess";
        HashMap<String, String> hashMap = new HashMap<>(16);
        hashMap.put("assessId", assessId + "");
        hashMap.put("replyContent", replyContent);
        String post = HttpClientUtil.post(url, JSONObject.toJSONString(hashMap));
        return post;
    }

}
